import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core';

@Directive({
  selector: '[appIshide]'
})
export class IshideDirective {

  private hasView = false;

  @Input() set appIshide(isHide: boolean) {
    if (!isHide && !this.hasView) {
      this.viewContainerRef.createEmbeddedView(this.templateRef);
      this.hasView = true;
    } else if (isHide && this.hasView) {
      this.viewContainerRef.clear();
      this.hasView = false;
    }
  }

  constructor(
    private templateRef: TemplateRef<any>,
    private viewContainerRef: ViewContainerRef,
  ) { }

}
